#include "readeredit.h"
#include "ui_readeredit.h"

readerEdit::readerEdit(User_Info user_info,QWidget *parent) :
    QWidget(parent),
    ui(new Ui::readerEdit)
{
    ui->setupUi(this);

    user = user_info;

    ui->lineEdit_Address->setText(user.address);
    ui->lineEdit_birthday->setText(user.birthday);
    ui->lineEdit_email->setText(user.email);
    ui->lineEdit_password->setText(user.password);
    ui->lineEdit_realname->setText(user.realName);
    ui->lineEdit_sex->setText(user.sex);
    ui->lineEdit_tel->setText(user.tel);


    ui->pushButton->setStyleSheet(
                "QPushButton{"
                "color: rgb(0, 0, 0);"
                "border:2px groove gray;"
                "border-color: rgb(0, 0, 0);"
                "border-radius:10px;"
                "background-color: rgba(20,196,188, 210);"
                "font:28px '宋体';}"
  "QPushButton::hover{"
                "border:2px groove gray;"
                "border-color: rgb(255, 255, 255);"
                "background-color: rgba(251,102,102, 200);"
                "color:rgb(255,255,255);}"
   "QPushButton::pressed{"
                "color: rgb(255, 0, 0);"
                "border:2px groove gray;"
                "border-color: rgb(255, 0, 0);"
                "background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(20,196,188, 210), stop:1 rgba(251,102,102, 200));}");


}

readerEdit::~readerEdit()
{
    delete ui;
}

void readerEdit::on_pushButton_clicked()
{
    user.address = ui->lineEdit_Address->text();
    user.birthday = ui->lineEdit_birthday->text();
    user.email = ui->lineEdit_email->text();
    user.password = ui->lineEdit_password->text();
    user.realName = ui->lineEdit_realname->text();
    user.sex = ui->lineEdit_sex->text();
    user.tel = ui->lineEdit_tel->text();
    emit signals_UserInfo(user);
    ////在这里添加更新数据库信息的
    QString sql = QString("UPDATE reader_info SET password='%0', realName='%1', sex='%2', birthday='%3', address='%4', tel='%5', email='%6' WHERE readerNumber='%7'")
            .arg(
                user.password,
                user.realName,
                user.sex,
                user.birthday,
                user.address,
                user.tel,
                user.email,
                user.readerNumber
                );
    DBOperation::getInstance()->operate(sql);

    QMessageBox::about(this,"提示","更新成功");
    this->close();
}
